package com.topnav.mc.document.bean;

import lombok.Data;
import org.springframework.format.datetime.standard.DateTimeContext;

/**
 * 文件统计
 */
@Data
public class DocumentStatisticsBean {
    private Integer fileCount;
    private Long fileSize;
    private Long duration;

    private String fileSizeStr;
    private String durationStr;

    public String getFileSizeStr(){
        if (fileSize == null){return "0";}
        if (fileSize < 1024){return fileSize+"B";}
        long k = fileSize / 1024;
        if(k==0)
            return "<1K";
        long m = k / 1024;
        k = k % 1024;
        if(m==0)
            return k+"K";
        long g = m / 1024;
        m = m % 1024;
        if(g==0)
            return m+"M"+k+"K";
        return g+"G"+ m+"M"+k+"K";


    }

    public String getDurationStr(){
        duration=duration==null?0L:duration;
        String dStr = durationToStr(duration);

        if ("<1秒".equals(dStr)){
            return "0";
        }
        return dStr;

    }

    private String durationToStr(Long duration){
        if (duration==0L){
            return "0";
        }else{
            long s=duration / 1000;
            if (s==0){
                return "0";
            }
            long m=s / 60;
            s = s % 60;
            if (m==0){
                return s + "秒";
            }
            long h=m % 60;
            m = m % 60;
            if (h == 0){
                return m+"分"+s+"秒";
            }
            return h+"时"+m+"分"+s+"秒";
        }
    }


}
